package com.zfast.config.vo;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.stereotype.Component;

import java.io.Serializable;

@Data
@Component
@ApiModel
public class CommonResult<E> implements Serializable {
    @ApiModelProperty(name = "code",notes = "状态码")
    private Integer code;
    @ApiModelProperty(name = "state",notes = "状态 true：操作成功  false：操作失败")
    Boolean state;
    @ApiModelProperty(name = "message",notes = "执行结果消息提示信息")
    String message;
    @ApiModelProperty(name = "value",notes = "返回参数")
    E value;
    //region 快速文字回复
    public void ajaxFalse(String message) {
        this.state = false;
        this.message = message;
        this.value = null;
        this.code = null;
    }

    public void ajaxTrue(String message) {
        this.state = true;
        this.message = message;
        this.value = null;
        this.code = null;
    }
    //endregion
    //region 初始化方法
    public CommonResult() {
        this.state = true;
    }

    public CommonResult(boolean state, String message) {
        this(state, message, null);
    }

    public CommonResult(boolean state, String message, E value) {
        this(state, message, value, (Integer)null);
    }

    public CommonResult(boolean state, String message, E value, Integer code) {
        this.state = true;
        this.state = state;
        this.message = message;
        this.value = value;
        this.code = code;
    }
    //endregion
}
